<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>blockquote.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_editor_plugins_blockquote.js.html">blockquote.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2008 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview goog.editor plugin to handle splitting block quotes.
<a name="line17"></a> *
<a name="line18"></a> */
<a name="line19"></a>
<a name="line20"></a>goog.provide(&#39;goog.editor.plugins.Blockquote&#39;);
<a name="line21"></a>
<a name="line22"></a>goog.require(&#39;goog.debug.Logger&#39;);
<a name="line23"></a>goog.require(&#39;goog.dom&#39;);
<a name="line24"></a>goog.require(&#39;goog.dom.NodeType&#39;);
<a name="line25"></a>goog.require(&#39;goog.dom.TagName&#39;);
<a name="line26"></a>goog.require(&#39;goog.dom.classes&#39;);
<a name="line27"></a>goog.require(&#39;goog.editor.BrowserFeature&#39;);
<a name="line28"></a>goog.require(&#39;goog.editor.Command&#39;);
<a name="line29"></a>goog.require(&#39;goog.editor.Plugin&#39;);
<a name="line30"></a>goog.require(&#39;goog.editor.node&#39;);
<a name="line31"></a>goog.require(&#39;goog.functions&#39;);
<a name="line32"></a>
<a name="line33"></a>
<a name="line34"></a>
<a name="line35"></a>/**
<a name="line36"></a> * Plugin to handle splitting block quotes.  This plugin does nothing on its
<a name="line37"></a> * own and should be used in conjunction with EnterHandler or one of its
<a name="line38"></a> * subclasses.
<a name="line39"></a> * @param {boolean} requiresClassNameToSplit Whether to split only blockquotes
<a name="line40"></a> *     that have the given classname.
<a name="line41"></a> * @param {string=} opt_className The classname to apply to generated
<a name="line42"></a> *     blockquotes.  Defaults to &#39;tr_bq&#39;.
<a name="line43"></a> * @constructor
<a name="line44"></a> * @extends {goog.editor.Plugin}
<a name="line45"></a> */
<a name="line46"></a>goog.editor.plugins.Blockquote = function(requiresClassNameToSplit,
<a name="line47"></a>    opt_className) {
<a name="line48"></a>  goog.editor.Plugin.call(this);
<a name="line49"></a>
<a name="line50"></a>  /**
<a name="line51"></a>   * Whether we only split blockquotes that have {@link classname}, or whether
<a name="line52"></a>   * all blockquote tags should be split on enter.
<a name="line53"></a>   * @type {boolean}
<a name="line54"></a>   * @private
<a name="line55"></a>   */
<a name="line56"></a>  this.requiresClassNameToSplit_ = requiresClassNameToSplit;
<a name="line57"></a>
<a name="line58"></a>  /**
<a name="line59"></a>   * Classname to put on blockquotes that are generated via the toolbar for
<a name="line60"></a>   * blockquote, so that we can internally distinguish these from blockquotes
<a name="line61"></a>   * that are used for indentation.  This classname can be over-ridden by
<a name="line62"></a>   * clients for styling or other purposes.
<a name="line63"></a>   * @type {string}
<a name="line64"></a>   * @private
<a name="line65"></a>   */
<a name="line66"></a>  this.className_ = opt_className || goog.getCssName(&#39;tr_bq&#39;);
<a name="line67"></a>};
<a name="line68"></a>goog.inherits(goog.editor.plugins.Blockquote, goog.editor.Plugin);
<a name="line69"></a>
<a name="line70"></a>
<a name="line71"></a>/**
<a name="line72"></a> * Command implemented by this plugin.
<a name="line73"></a> * @type {string}
<a name="line74"></a> */
<a name="line75"></a>goog.editor.plugins.Blockquote.SPLIT_COMMAND = &#39;+splitBlockquote&#39;;
<a name="line76"></a>
<a name="line77"></a>
<a name="line78"></a>/**
<a name="line79"></a> * Class ID used to identify this plugin.
<a name="line80"></a> * @type {string}
<a name="line81"></a> */
<a name="line82"></a>goog.editor.plugins.Blockquote.CLASS_ID = &#39;Blockquote&#39;;
<a name="line83"></a>
<a name="line84"></a>
<a name="line85"></a>/**
<a name="line86"></a> * Logging object.
<a name="line87"></a> * @type {goog.debug.Logger}
<a name="line88"></a> * @protected
<a name="line89"></a> * @override
<a name="line90"></a> */
<a name="line91"></a>goog.editor.plugins.Blockquote.prototype.logger =
<a name="line92"></a>    goog.debug.Logger.getLogger(&#39;goog.editor.plugins.Blockquote&#39;);
<a name="line93"></a>
<a name="line94"></a>
<a name="line95"></a>/** @override */
<a name="line96"></a>goog.editor.plugins.Blockquote.prototype.getTrogClassId = function() {
<a name="line97"></a>  return goog.editor.plugins.Blockquote.CLASS_ID;
<a name="line98"></a>};
<a name="line99"></a>
<a name="line100"></a>
<a name="line101"></a>/**
<a name="line102"></a> * Since our exec command is always called from elsewhere, we make it silent.
<a name="line103"></a> * @override
<a name="line104"></a> */
<a name="line105"></a>goog.editor.plugins.Blockquote.prototype.isSilentCommand = goog.functions.TRUE;
<a name="line106"></a>
<a name="line107"></a>
<a name="line108"></a>/**
<a name="line109"></a> * Checks if a node is a blockquote node.  If isAlreadySetup is set, it also
<a name="line110"></a> * makes sure the node has the blockquote classname applied.  Otherwise, it
<a name="line111"></a> * ensures that the blockquote does not already have the classname applied.
<a name="line112"></a> * @param {Node} node DOM node to check.
<a name="line113"></a> * @param {boolean} isAlreadySetup True to enforce that the classname must be
<a name="line114"></a> *                  set in order for it to count as a blockquote, false to
<a name="line115"></a> *                  enforce that the classname must not be set in order for
<a name="line116"></a> *                  it to count as a blockquote.
<a name="line117"></a> * @param {boolean} requiresClassNameToSplit Whether only blockquotes with the
<a name="line118"></a> *     class name should be split.
<a name="line119"></a> * @param {string} className The official blockquote class name.
<a name="line120"></a> * @return {boolean} Whether node is a blockquote and if isAlreadySetup is
<a name="line121"></a> *    true, then whether this is a setup blockquote.
<a name="line122"></a> * @deprecated Use {@link #isSplittableBlockquote},
<a name="line123"></a> *     {@link #isSetupBlockquote}, or {@link #isUnsetupBlockquote} instead
<a name="line124"></a> *     since this has confusing behavior.
<a name="line125"></a> */
<a name="line126"></a>goog.editor.plugins.Blockquote.isBlockquote = function(node, isAlreadySetup,
<a name="line127"></a>    requiresClassNameToSplit, className) {
<a name="line128"></a>  if (node.tagName != goog.dom.TagName.BLOCKQUOTE) {
<a name="line129"></a>    return false;
<a name="line130"></a>  }
<a name="line131"></a>  if (!requiresClassNameToSplit) {
<a name="line132"></a>    return isAlreadySetup;
<a name="line133"></a>  }
<a name="line134"></a>  var hasClassName = goog.dom.classes.has(/** @type {Element} */ (node),
<a name="line135"></a>      className);
<a name="line136"></a>  return isAlreadySetup ? hasClassName : !hasClassName;
<a name="line137"></a>};
<a name="line138"></a>
<a name="line139"></a>
<a name="line140"></a>/**
<a name="line141"></a> * Checks if a node is a blockquote which can be split. A splittable blockquote
<a name="line142"></a> * meets the following criteria:
<a name="line143"></a> * &lt;ol&gt;
<a name="line144"></a> *   &lt;li&gt;Node is a blockquote element&lt;/li&gt;
<a name="line145"></a> *   &lt;li&gt;Node has the blockquote classname if the classname is required to
<a name="line146"></a> *       split&lt;/li&gt;
<a name="line147"></a> * &lt;/ol&gt;
<a name="line148"></a> *
<a name="line149"></a> * @param {Node} node DOM node in question.
<a name="line150"></a> * @return {boolean} Whether the node is a splittable blockquote.
<a name="line151"></a> */
<a name="line152"></a>goog.editor.plugins.Blockquote.prototype.isSplittableBlockquote =
<a name="line153"></a>    function(node) {
<a name="line154"></a>  if (node.tagName != goog.dom.TagName.BLOCKQUOTE) {
<a name="line155"></a>    return false;
<a name="line156"></a>  }
<a name="line157"></a>
<a name="line158"></a>  if (!this.requiresClassNameToSplit_) {
<a name="line159"></a>    return true;
<a name="line160"></a>  }
<a name="line161"></a>
<a name="line162"></a>  return goog.dom.classes.has(node, this.className_);
<a name="line163"></a>};
<a name="line164"></a>
<a name="line165"></a>
<a name="line166"></a>/**
<a name="line167"></a> * Checks if a node is a blockquote element which has been setup.
<a name="line168"></a> * @param {Node} node DOM node to check.
<a name="line169"></a> * @return {boolean} Whether the node is a blockquote with the required class
<a name="line170"></a> *     name applied.
<a name="line171"></a> */
<a name="line172"></a>goog.editor.plugins.Blockquote.prototype.isSetupBlockquote =
<a name="line173"></a>    function(node) {
<a name="line174"></a>  return node.tagName == goog.dom.TagName.BLOCKQUOTE &amp;&amp;
<a name="line175"></a>      goog.dom.classes.has(node, this.className_);
<a name="line176"></a>};
<a name="line177"></a>
<a name="line178"></a>
<a name="line179"></a>/**
<a name="line180"></a> * Checks if a node is a blockquote element which has not been setup yet.
<a name="line181"></a> * @param {Node} node DOM node to check.
<a name="line182"></a> * @return {boolean} Whether the node is a blockquote without the required
<a name="line183"></a> *     class name applied.
<a name="line184"></a> */
<a name="line185"></a>goog.editor.plugins.Blockquote.prototype.isUnsetupBlockquote =
<a name="line186"></a>    function(node) {
<a name="line187"></a>  return node.tagName == goog.dom.TagName.BLOCKQUOTE &amp;&amp;
<a name="line188"></a>      !this.isSetupBlockquote(node);
<a name="line189"></a>};
<a name="line190"></a>
<a name="line191"></a>
<a name="line192"></a>/**
<a name="line193"></a> * Gets the class name required for setup blockquotes.
<a name="line194"></a> * @return {string} The blockquote class name.
<a name="line195"></a> */
<a name="line196"></a>goog.editor.plugins.Blockquote.prototype.getBlockquoteClassName = function() {
<a name="line197"></a>  return this.className_;
<a name="line198"></a>};
<a name="line199"></a>
<a name="line200"></a>
<a name="line201"></a>/**
<a name="line202"></a> * Helper routine which walks up the tree to find the topmost
<a name="line203"></a> * ancestor with only a single child. The ancestor node or the original
<a name="line204"></a> * node (if no ancestor was found) is then removed from the DOM.
<a name="line205"></a> *
<a name="line206"></a> * @param {Node} node The node whose ancestors have to be searched.
<a name="line207"></a> * @param {Node} root The root node to stop the search at.
<a name="line208"></a> * @private
<a name="line209"></a> */
<a name="line210"></a>goog.editor.plugins.Blockquote.findAndRemoveSingleChildAncestor_ = function(
<a name="line211"></a>    node, root) {
<a name="line212"></a>  var predicateFunc = function(parentNode) {
<a name="line213"></a>    return parentNode != root &amp;&amp; parentNode.childNodes.length == 1;
<a name="line214"></a>  }
<a name="line215"></a>  var ancestor = goog.editor.node.findHighestMatchingAncestor(node,
<a name="line216"></a>      predicateFunc);
<a name="line217"></a>  if (!ancestor) {
<a name="line218"></a>    ancestor = node;
<a name="line219"></a>  }
<a name="line220"></a>  goog.dom.removeNode(ancestor);
<a name="line221"></a>};
<a name="line222"></a>
<a name="line223"></a>
<a name="line224"></a>/**
<a name="line225"></a> * Remove every nodes from the DOM tree that are all white space nodes.
<a name="line226"></a> * @param {Array.&lt;Node&gt;} nodes Nodes to be checked.
<a name="line227"></a> * @private
<a name="line228"></a> */
<a name="line229"></a>goog.editor.plugins.Blockquote.removeAllWhiteSpaceNodes_ = function(nodes) {
<a name="line230"></a>  for (var i = 0; i &lt; nodes.length; ++i) {
<a name="line231"></a>    if (goog.editor.node.isEmpty(nodes[i], true)) {
<a name="line232"></a>      goog.dom.removeNode(nodes[i]);
<a name="line233"></a>    }
<a name="line234"></a>  }
<a name="line235"></a>};
<a name="line236"></a>
<a name="line237"></a>
<a name="line238"></a>/** @override */
<a name="line239"></a>goog.editor.plugins.Blockquote.prototype.isSupportedCommand = function(
<a name="line240"></a>    command) {
<a name="line241"></a>  return command == goog.editor.plugins.Blockquote.SPLIT_COMMAND;
<a name="line242"></a>};
<a name="line243"></a>
<a name="line244"></a>
<a name="line245"></a>/**
<a name="line246"></a> * Splits a quoted region if any.  To be called on a key press event.  When this
<a name="line247"></a> * function returns true, the event that caused it to be called should be
<a name="line248"></a> * canceled.
<a name="line249"></a> * @param {string} command The command to execute.
<a name="line250"></a> * @param {...*} var_args Single additional argument representing the
<a name="line251"></a> *     current cursor position.  In IE, it is a single node.  In any other
<a name="line252"></a> *     browser, it is an object with a {@code node} key and an {@code offset}
<a name="line253"></a> *     key.
<a name="line254"></a> * @return {boolean|undefined} Boolean true when the quoted region has been
<a name="line255"></a> *     split, false or undefined otherwise.
<a name="line256"></a> * @override
<a name="line257"></a> */
<a name="line258"></a>goog.editor.plugins.Blockquote.prototype.execCommandInternal = function(
<a name="line259"></a>    command, var_args) {
<a name="line260"></a>  var pos = arguments[1];
<a name="line261"></a>  if (command == goog.editor.plugins.Blockquote.SPLIT_COMMAND &amp;&amp; pos &amp;&amp;
<a name="line262"></a>      (this.className_ || !this.requiresClassNameToSplit_)) {
<a name="line263"></a>    return goog.editor.BrowserFeature.HAS_W3C_RANGES ?
<a name="line264"></a>        this.splitQuotedBlockW3C_(pos) :
<a name="line265"></a>        this.splitQuotedBlockIE_(/** @type {Node} */ (pos));
<a name="line266"></a>  }
<a name="line267"></a>};
<a name="line268"></a>
<a name="line269"></a>
<a name="line270"></a>/**
<a name="line271"></a> * Version of splitQuotedBlock_ that uses W3C ranges.
<a name="line272"></a> * @param {Object} anchorPos The current cursor position.
<a name="line273"></a> * @return {boolean} Whether the blockquote was split.
<a name="line274"></a> * @private
<a name="line275"></a> */
<a name="line276"></a>goog.editor.plugins.Blockquote.prototype.splitQuotedBlockW3C_ =
<a name="line277"></a>    function(anchorPos) {
<a name="line278"></a>  var cursorNode = anchorPos.node;
<a name="line279"></a>  var quoteNode = goog.editor.node.findTopMostEditableAncestor(
<a name="line280"></a>      cursorNode.parentNode, goog.bind(this.isSplittableBlockquote, this));
<a name="line281"></a>
<a name="line282"></a>  var secondHalf, textNodeToRemove;
<a name="line283"></a>  var insertTextNode = false;
<a name="line284"></a>  // There are two special conditions that we account for here.
<a name="line285"></a>  //
<a name="line286"></a>  // 1. Whenever the cursor is after (one&lt;BR&gt;|) or just before a BR element
<a name="line287"></a>  //    (one|&lt;BR&gt;) and the user presses enter, the second quoted block starts
<a name="line288"></a>  //    with a BR which appears to the user as an extra newline. This stems
<a name="line289"></a>  //    from the fact that we create two text nodes as our split boundaries
<a name="line290"></a>  //    and the BR becomes a part of the second half because of this.
<a name="line291"></a>  //
<a name="line292"></a>  // 2. When the cursor is at the end of a text node with no siblings and
<a name="line293"></a>  //    the user presses enter, the second blockquote might contain a
<a name="line294"></a>  //    empty subtree that ends in a 0 length text node. We account for that
<a name="line295"></a>  //    as a post-splitting operation.
<a name="line296"></a>  if (quoteNode) {
<a name="line297"></a>
<a name="line298"></a>    // selection is in a line that has text in it
<a name="line299"></a>    if (cursorNode.nodeType == goog.dom.NodeType.TEXT) {
<a name="line300"></a>      if (anchorPos.offset == cursorNode.length) {
<a name="line301"></a>        var siblingNode = cursorNode.nextSibling;
<a name="line302"></a>
<a name="line303"></a>        // This accounts for the condition where the cursor appears at the
<a name="line304"></a>        // end of a text node and right before the BR eg: one|&lt;BR&gt;. We ensure
<a name="line305"></a>        // that we split on the BR in that case.
<a name="line306"></a>        if (siblingNode &amp;&amp; siblingNode.tagName == goog.dom.TagName.BR) {
<a name="line307"></a>          cursorNode = siblingNode;
<a name="line308"></a>          // This might be null but splitDomTreeAt accounts for the null case.
<a name="line309"></a>          secondHalf = siblingNode.nextSibling;
<a name="line310"></a>        } else {
<a name="line311"></a>          textNodeToRemove = cursorNode.splitText(anchorPos.offset);
<a name="line312"></a>          secondHalf = textNodeToRemove;
<a name="line313"></a>        }
<a name="line314"></a>      } else {
<a name="line315"></a>        secondHalf = cursorNode.splitText(anchorPos.offset);
<a name="line316"></a>      }
<a name="line317"></a>    } else if (cursorNode.tagName == goog.dom.TagName.BR) {
<a name="line318"></a>      // This might be null but splitDomTreeAt accounts for the null case.
<a name="line319"></a>      secondHalf = cursorNode.nextSibling;
<a name="line320"></a>    } else {
<a name="line321"></a>      // The selection is in a line that is empty, with more than 1 level
<a name="line322"></a>      // of quote.
<a name="line323"></a>      insertTextNode = true;
<a name="line324"></a>    }
<a name="line325"></a>  } else {
<a name="line326"></a>    // Check if current node is a quote node.
<a name="line327"></a>    // This will happen if user clicks in an empty line in the quote,
<a name="line328"></a>    // when there is 1 level of quote.
<a name="line329"></a>    if (this.isSetupBlockquote(cursorNode)) {
<a name="line330"></a>      quoteNode = cursorNode;
<a name="line331"></a>      insertTextNode = true;
<a name="line332"></a>    }
<a name="line333"></a>  }
<a name="line334"></a>
<a name="line335"></a>  if (insertTextNode) {
<a name="line336"></a>    // Create two empty text nodes to split between.
<a name="line337"></a>    cursorNode = this.insertEmptyTextNodeBeforeRange_();
<a name="line338"></a>    secondHalf = this.insertEmptyTextNodeBeforeRange_();
<a name="line339"></a>  }
<a name="line340"></a>
<a name="line341"></a>  if (!quoteNode) {
<a name="line342"></a>    return false;
<a name="line343"></a>  }
<a name="line344"></a>
<a name="line345"></a>  secondHalf = goog.editor.node.splitDomTreeAt(cursorNode, secondHalf,
<a name="line346"></a>      quoteNode);
<a name="line347"></a>  goog.dom.insertSiblingAfter(secondHalf, quoteNode);
<a name="line348"></a>
<a name="line349"></a>  // Set the insertion point.
<a name="line350"></a>  var dh = this.getFieldDomHelper();
<a name="line351"></a>  var tagToInsert =
<a name="line352"></a>      this.getFieldObject().queryCommandValue(
<a name="line353"></a>          goog.editor.Command.DEFAULT_TAG) ||
<a name="line354"></a>          goog.dom.TagName.DIV;
<a name="line355"></a>  var container = dh.createElement(/** @type {string} */ (tagToInsert));
<a name="line356"></a>  container.innerHTML = &#39;&amp;nbsp;&#39;;  // Prevent the div from collapsing.
<a name="line357"></a>  quoteNode.parentNode.insertBefore(container, secondHalf);
<a name="line358"></a>  dh.getWindow().getSelection().collapse(container, 0);
<a name="line359"></a>
<a name="line360"></a>  // We need to account for the condition where the second blockquote
<a name="line361"></a>  // might contain an empty DOM tree. This arises from trying to split
<a name="line362"></a>  // at the end of an empty text node. We resolve this by walking up the tree
<a name="line363"></a>  // till we either reach the blockquote or till we hit a node with more
<a name="line364"></a>  // than one child. The resulting node is then removed from the DOM.
<a name="line365"></a>  if (textNodeToRemove) {
<a name="line366"></a>    goog.editor.plugins.Blockquote.findAndRemoveSingleChildAncestor_(
<a name="line367"></a>        textNodeToRemove, secondHalf);
<a name="line368"></a>  }
<a name="line369"></a>
<a name="line370"></a>  goog.editor.plugins.Blockquote.removeAllWhiteSpaceNodes_(
<a name="line371"></a>      [quoteNode, secondHalf]);
<a name="line372"></a>  return true;
<a name="line373"></a>};
<a name="line374"></a>
<a name="line375"></a>
<a name="line376"></a>/**
<a name="line377"></a> * Inserts an empty text node before the field&#39;s range.
<a name="line378"></a> * @return {!Node} The empty text node.
<a name="line379"></a> * @private
<a name="line380"></a> */
<a name="line381"></a>goog.editor.plugins.Blockquote.prototype.insertEmptyTextNodeBeforeRange_ =
<a name="line382"></a>    function() {
<a name="line383"></a>  var range = this.getFieldObject().getRange();
<a name="line384"></a>  var node = this.getFieldDomHelper().createTextNode(&#39;&#39;);
<a name="line385"></a>  range.insertNode(node, true);
<a name="line386"></a>  return node;
<a name="line387"></a>};
<a name="line388"></a>
<a name="line389"></a>
<a name="line390"></a>/**
<a name="line391"></a> * IE version of splitQuotedBlock_.
<a name="line392"></a> * @param {Node} splitNode The current cursor position.
<a name="line393"></a> * @return {boolean} Whether the blockquote was split.
<a name="line394"></a> * @private
<a name="line395"></a> */
<a name="line396"></a>goog.editor.plugins.Blockquote.prototype.splitQuotedBlockIE_ =
<a name="line397"></a>    function(splitNode) {
<a name="line398"></a>  var dh = this.getFieldDomHelper();
<a name="line399"></a>  var quoteNode = goog.editor.node.findTopMostEditableAncestor(
<a name="line400"></a>      splitNode.parentNode, goog.bind(this.isSplittableBlockquote, this));
<a name="line401"></a>
<a name="line402"></a>  if (!quoteNode) {
<a name="line403"></a>    return false;
<a name="line404"></a>  }
<a name="line405"></a>
<a name="line406"></a>  var clone = splitNode.cloneNode(false);
<a name="line407"></a>
<a name="line408"></a>  // Whenever the cursor is just before a BR element (one|&lt;BR&gt;) and the user
<a name="line409"></a>  // presses enter, the second quoted block starts with a BR which appears
<a name="line410"></a>  // to the user as an extra newline. This stems from the fact that the
<a name="line411"></a>  // dummy span that we create (splitNode) occurs before the BR and we split
<a name="line412"></a>  // on that.
<a name="line413"></a>  if (splitNode.nextSibling &amp;&amp;
<a name="line414"></a>      splitNode.nextSibling.tagName == goog.dom.TagName.BR) {
<a name="line415"></a>    splitNode = splitNode.nextSibling;
<a name="line416"></a>  }
<a name="line417"></a>  var secondHalf = goog.editor.node.splitDomTreeAt(splitNode, clone, quoteNode);
<a name="line418"></a>  goog.dom.insertSiblingAfter(secondHalf, quoteNode);
<a name="line419"></a>
<a name="line420"></a>  // Set insertion point.
<a name="line421"></a>  var tagToInsert =
<a name="line422"></a>      this.getFieldObject().queryCommandValue(
<a name="line423"></a>          goog.editor.Command.DEFAULT_TAG) ||
<a name="line424"></a>          goog.dom.TagName.DIV;
<a name="line425"></a>  var div = dh.createElement(/** @type {string} */ (tagToInsert));
<a name="line426"></a>  quoteNode.parentNode.insertBefore(div, secondHalf);
<a name="line427"></a>
<a name="line428"></a>  // The div needs non-whitespace contents in order for the insertion point
<a name="line429"></a>  // to get correctly inserted.
<a name="line430"></a>  div.innerHTML = &#39;&amp;nbsp;&#39;;
<a name="line431"></a>
<a name="line432"></a>  // Moving the range 1 char isn&#39;t enough when you have markup.
<a name="line433"></a>  // This moves the range to the end of the nbsp.
<a name="line434"></a>  var range = dh.getDocument().selection.createRange();
<a name="line435"></a>  range.moveToElementText(splitNode);
<a name="line436"></a>  range.move(&#39;character&#39;, 2);
<a name="line437"></a>  range.select();
<a name="line438"></a>
<a name="line439"></a>  // Remove the no-longer-necessary nbsp.
<a name="line440"></a>  div.innerHTML = &#39;&#39;;
<a name="line441"></a>
<a name="line442"></a>  // Clear the original selection.
<a name="line443"></a>  range.pasteHTML(&#39;&#39;);
<a name="line444"></a>
<a name="line445"></a>  // We need to remove clone from the DOM but just removing clone alone will
<a name="line446"></a>  // not suffice. Let&#39;s assume we have the following DOM structure and the
<a name="line447"></a>  // cursor is placed after the first numbered list item &quot;one&quot;.
<a name="line448"></a>  //
<a name="line449"></a>  // &lt;blockquote class=&quot;gmail-quote&quot;&gt;
<a name="line450"></a>  //   &lt;div&gt;&lt;div&gt;a&lt;/div&gt;&lt;ol&gt;&lt;li&gt;one|&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;
<a name="line451"></a>  //   &lt;div&gt;b&lt;/div&gt;
<a name="line452"></a>  // &lt;/blockquote&gt;
<a name="line453"></a>  //
<a name="line454"></a>  // After pressing enter, we have the following structure.
<a name="line455"></a>  //
<a name="line456"></a>  // &lt;blockquote class=&quot;gmail-quote&quot;&gt;
<a name="line457"></a>  //   &lt;div&gt;&lt;div&gt;a&lt;/div&gt;&lt;ol&gt;&lt;li&gt;one|&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;
<a name="line458"></a>  // &lt;/blockquote&gt;
<a name="line459"></a>  // &lt;div&gt;&amp;nbsp;&lt;/div&gt;
<a name="line460"></a>  // &lt;blockquote class=&quot;gmail-quote&quot;&gt;
<a name="line461"></a>  //   &lt;div&gt;&lt;ol&gt;&lt;li&gt;&lt;span id=&quot;&quot;&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;
<a name="line462"></a>  //   &lt;div&gt;b&lt;/div&gt;
<a name="line463"></a>  // &lt;/blockquote&gt;
<a name="line464"></a>  //
<a name="line465"></a>  // The clone is contained in a subtree which should be removed. This stems
<a name="line466"></a>  // from the fact that we invoke splitDomTreeAt with the dummy span
<a name="line467"></a>  // as the starting splitting point and this results in the empty subtree
<a name="line468"></a>  // &lt;div&gt;&lt;ol&gt;&lt;li&gt;&lt;span id=&quot;&quot;&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;.
<a name="line469"></a>  //
<a name="line470"></a>  // We resolve this by walking up the tree till we either reach the
<a name="line471"></a>  // blockquote or till we hit a node with more than one child. The resulting
<a name="line472"></a>  // node is then removed from the DOM.
<a name="line473"></a>  goog.editor.plugins.Blockquote.findAndRemoveSingleChildAncestor_(
<a name="line474"></a>      clone, secondHalf);
<a name="line475"></a>
<a name="line476"></a>  goog.editor.plugins.Blockquote.removeAllWhiteSpaceNodes_(
<a name="line477"></a>      [quoteNode, secondHalf]);
<a name="line478"></a>  return true;
<a name="line479"></a>};
</pre>


</body>
</html>
